package com.winning.pregnancyandroid.activities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.example.pregnancyandroid.R;

import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.SimpleAdapter;

public class ModesActivity extends Activity {
	private GridView menugrid = null;
	private SimpleAdapter mySimplerAdapter = null;
	private List<Map<String,Integer>> list = new ArrayList<Map<String,Integer>>();
	@SuppressLint("NewApi")  //一定要加这个，不然就老实的去写线程访问吧
	@Override
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()       
        .detectDiskReads()       
        .detectDiskWrites()       
        .detectNetwork()   // or .detectAll() for all detectable problems       
        .penaltyLog()       
        .build());       
		StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()       
        .detectLeakedSqlLiteObjects()    
        .penaltyLog()       
        .penaltyDeath()       
        .build());  
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏
		setContentView(R.layout.activity_modes);


		findViews(); //初始化样式
		
	
		
		initData();//初始化数据

		setListener();
	}

 
	public  void findViews(){
		menugrid = (GridView) findViewById(R.id.menugrid);
	}
	
	
	public void initData(){
		//菜单是写死的
		Integer[] data = {R.drawable.myappoint,R.drawable.myproccess,R.drawable.myexamination,R.drawable.myeatimate,R.drawable.mysigns,
				R.drawable.mysetting,R.drawable.babypicture,R.drawable.babysize,R.drawable.babysound};
		for(int i = 0;i < data.length;i++){
			Map<String, Integer> map = new HashMap<String, Integer>();
			map.put("menudata", data[i]);
			list.add(map);
		}

		mySimplerAdapter = new SimpleAdapter(this, list, R.layout.modes_item, new String[]{"menudata"}, new int[]{R.id.menudata});
		menugrid.setAdapter(mySimplerAdapter);
	}
	
	
	private void setListener(){
		menugrid.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				switch(position){
				case 5:
					Intent it = new Intent(ModesActivity.this,LoginActivity.class );
					startActivity(it);
					break;	
				}
			}
		});
	}

}
